import os

from gis.common.jsonlogger import JsonFormatter

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

SECRET_KEY = "n)-&0h&#yoy9w!36joykw#-hq12vg!63khct0*9c-4@_n@qu1o"

DEBUG = True

ALLOWED_HOSTS = ["*"]

INSTALLED_APPS = [
    "itpay.core.mch",
    "itpay.core.agency",
    "itpay.core.admin_ext",
    "itpay.core.recharge_order",
    "gis.admin.apps.AdminConfig",
    "gis.common.timer",
    "django.contrib.sessions",
    "test_without_migrations",
]

MIDDLEWARE = [
    "itpay.server_api.base.middleware.TrackLoggerMiddleware",
    "gis.common.django_ext.middleware.ApiMiddleware",
]

ROOT_URLCONF = "itpay.server_api.urls"

LANGUAGE_CODE = "zh-cn"

TIME_ZONE = "Asia/Chongqing"

USE_I18N = False

USE_L10N = False

USE_TZ = False

# session有效期20分钟
SESSION_COOKIE_AGE = 20 * 60

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "simple": {"format": "%(levelname)s %(asctime)s %(message)s"},
        "json_stat": {"()": JsonFormatter, "format": "%(message)s"},
    },
    "handlers": {
        "console": {"class": "logging.StreamHandler"},
        "file": {
            "level": "DEBUG",
            "class": "logging.FileHandler",
            "filename": "/var/log/itpay_new_api/itpay_new_api.log",
            "formatter": "simple",
        },
        "maestro_file": {
            "level": "INFO",
            "class": "logging.handlers.WatchedFileHandler",
            "filename": "/var/log/itpay_new_admin/maestro.json",
            "formatter": "json_stat",
        },
    },
    "root": {"level": "DEBUG", "handlers": ["console", "file"]},
    "loggers": {
        "maestro": {"handlers": ["maestro_file"], "level": "INFO", "propagate": False}
    },
}

try:
    from itpay.conf.server import *  # noqa: F403 F401
except ImportError:
    import logging

    logging.warn("no env specified conf loaded, use default.")
    pass

try:
    from .env_settings import *  # noqa: F403 F401
except ImportError:
    import logging

    logging.warn("no env specified settings loaded, use default.")
    pass
